/*
  MapReduce Common Library
  by DongWoo Lee
*/

load("./common.js")
load("./json2.js")
load("./user.js")

/* Initialization MapReduce */
mr_init();

/* MapReduce Main */
/* Data Source --> Mapper --> Intermediate Data Storage */
for(i=0; i<mrSource.length; i++)
{
	Mapper(mrSource[i]);
}

/* Ordered key of Mapper */
/* mSourece --> Mapper --> mStore --> Reducer --> rStore */

/* Intermediate Data Storage --> Reducer --> Intermediate Data Storage */
for (var key in mStore)
{
	ret = Reducer(key, mStore[key], []);
	rStore[key] = ret;
}

/* Display mSource, mStore, rStore */
print("--------------");
a = JSON.stringify(mrSource);
print(a);
//showStore(mrSource);
print("--------------");
//showStore(mStore);
print("--------------");
showStore(rStore);
print("--------------");

/* Clear up MapReduce */
mr_close();
